package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.BsEmployeeEntity;
import io.renren.modules.app.entity.BsPostEntity;
import io.renren.modules.app.service.BsEmployeeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 员工表
 *
 */
@RestController
@RequestMapping("tb_bs_employee/bsemployee")
public class BsEmployeeController {
    @Autowired
    private BsEmployeeService bsEmployeeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tb_bs_employee:bsemployee:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsEmployeeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tb_bs_employee:bsemployee:info")
    public R info(@PathVariable("id") Long id){
		BsEmployeeEntity bsEmployee = bsEmployeeService.getById(id);

        return R.ok().put("bsEmployee", bsEmployee);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb_bs_employee:bsemployee:save")
    public R save(@RequestBody BsEmployeeEntity bsEmployee){
        bsEmployeeService.saveEmploy(bsEmployee);
		//bsEmployeeService.save(bsEmployee);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb_bs_employee:bsemployee:update")
    public R update(@RequestBody BsEmployeeEntity bsEmployee){
        bsEmployeeService.updateEmploy(bsEmployee);
		//bsEmployeeService.updateById(bsEmployee);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb_bs_employee:bsemployee:delete")
    public R delete(@RequestBody Long[] ids){
		bsEmployeeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 根据部门获取岗位信息
     */
    @RequestMapping("getPostByDepart")
    public R getPostByDepart(@RequestParam("departId") String departId){
        List<BsPostEntity> list = bsEmployeeService.getPostByDepart(departId);
        return R.ok(list);
    }

    /**
     * 岗位信息获取
     */
    @RequestMapping("getPostById")
    public R getPostById(@RequestParam("postId") String postId){
        BsPostEntity bsPost = bsEmployeeService.getPostById(postId);
        return R.ok(bsPost) ;
    }

}
